package utils

import (
	"gopkg.in/ini.v1"
	"income/model"
	"io"
	"log"
	"os"
)

var Logger = new(log.Logger)

func init() {
	initConifg()
	initLog()
}

func initConifg() {
	cfg, err := ini.Load("conf/my.ini")
	if err != nil {
		log.Fatal("Fail to read file: ", err)
	}
	cfg.Section("smtp").MapTo(model.SmtpPtr)
}

func initLog() {
	writer1 := os.Stdout
	writer2, err := os.OpenFile("logs/income.log", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0755)
	if err != nil {
		log.Fatalf("create file log.txt failed: %v", err)
	}

	Logger = log.New(io.MultiWriter(writer1, writer2), "[income]", log.LstdFlags)
}
